package com.cyf.filmDownload.config;

import lombok.Getter;
import java.io.InputStream;
import java.util.Properties;

@Getter
public class AppConfig {

    // 下载线程池大小
    public static int threadPoolSize;
    // 视频下载目录
    public static String videoDownloadDir;
    // 视频分片临时目录
    public static String tsTempDir;
    // 下载进度监听间隙
    public static int listeningInterval;
    // 视频分片下载失败重试次数
    public static int tsDownloadRetryCount;
    // 下载完毕后是否删除视频分片临时目录
    public static boolean isDeleteTsTempDir;
    // ffmpeg路径，用于视频合并
    public static String ffmpegPath;

    static {

        try (InputStream input = AppConfig.class.getResourceAsStream("/config.properties")) {
            Properties prop = new Properties();
            prop.load(input);
            threadPoolSize = Integer.parseInt(prop.getProperty("threadPoolSize"));
            videoDownloadDir = prop.getProperty("videoDownloadDir");
            tsTempDir = prop.getProperty("tsTempDir");
            tsDownloadRetryCount = Integer.parseInt(prop.getProperty("tsDownloadRetryCount"));
            isDeleteTsTempDir = prop.getProperty("isDeleteTsTempDir").equalsIgnoreCase("true");
            listeningInterval = Integer.parseInt(prop.getProperty("listeningInterval"));
            ffmpegPath = prop.getProperty("ffmpegPath");
            System.out.println();
        } catch (Exception e) {
            throw new RuntimeException("Failed to load config.properties", e);
        }
    }
}
